/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package form.output;

import br.entidade.Convenio;
import br.entidade.MascaraConvenio;
import br.entidade.business.Business;
import br.entidade.sft.SftCtrlHistorico;
import br.entidade.sft.SftInputAten;
import br.entidade.sft.SftInputNcon;
import br.entidade.sft.SftInputStat;
import br.entidade.sft.SftInputUnid;
import br.entidade.sft.SftOutputGlos;
import entidade.controle.OutputGlosCtrl;
import form.output.eraser.JDGlos;
import form.output.historico.JDGlosHist;
import form.util.Documents;
import java.awt.event.KeyEvent;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.RollbackException;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import br.data.bancodedados.CriaConexao;
import superior.mensagens.ErroMensagens;
import superior.sessao.Logger;

/**
 *
 * @author Adriano
 */
public class JPGlosa extends javax.swing.JPanel {

    /**
     * Creates new form JPGlosa
     */
    public JPGlosa() {
        initComponents();
        iniciarComponentes();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        obsFild = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jCStatus = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        osFild = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        atenFild = new javax.swing.JTextField();
        convFild = new javax.swing.JTextField();
        nConCombo = new javax.swing.JComboBox();
        valorFild = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        newButton = new javax.swing.JButton();
        infoButton = new javax.swing.JButton();
        refreshButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        uploadBoton = new javax.swing.JButton();
        numLabel = new javax.swing.JLabel();
        jScrollTabela = new javax.swing.JScrollPane();
        masterTable = new javax.swing.JTable();
        jScrollTabela = new javax.swing.JScrollPane();
        masterTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        lsm = masterTable.getSelectionModel();
        lsm.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    jTTabelaLinhaSelecionada(masterTable);
                }
            }
        });
        jBarradeProgresso = new javax.swing.JProgressBar();

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setMaximumSize(new java.awt.Dimension(970, 478));
        jPanel1.setMinimumSize(new java.awt.Dimension(970, 478));

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setMinimumSize(new java.awt.Dimension(798, 122));
        jPanel2.setName(""); // NOI18N

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), obsFild, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        obsFild.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                obsFildFocusLost(evt);
            }
        });
        obsFild.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                obsFildActionPerformed(evt);
            }
        });

        jLabel6.setText("Observação");

        jLabel7.setText("Situação");

        jCStatus.setMinimumSize(new java.awt.Dimension(169, 25));
        jCStatus.setPreferredSize(new java.awt.Dimension(169, 25));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), jCStatus, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jCStatus.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jCStatusFocusLost(evt);
            }
        });
        jCStatus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCStatusActionPerformed(evt);
            }
        });
        jCStatus.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jCStatusKeyPressed(evt);
            }
        });

        jLabel4.setText("Convenio");

        jLabel3.setText("Não Conformidade");

        jLabel1.setText("Atendente");

        osFild.setDocument(Documents.getDocuments().DigitaOS());
        osFild.setMinimumSize(new java.awt.Dimension(129, 25));
        osFild.setPreferredSize(new java.awt.Dimension(129, 25));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), osFild, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        osFild.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                osFildKeyReleased(evt);
            }
        });

        jLabel5.setText("OS");

        atenFild.setMinimumSize(new java.awt.Dimension(170, 25));
        atenFild.setPreferredSize(new java.awt.Dimension(170, 25));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), atenFild, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        atenFild.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                atenFildFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                atenFildFocusLost(evt);
            }
        });
        atenFild.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                atenFildKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                atenFildKeyReleased(evt);
            }
        });

        convFild.setMinimumSize(new java.awt.Dimension(170, 25));
        convFild.setPreferredSize(new java.awt.Dimension(170, 25));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), convFild, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        convFild.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                convFildFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                convFildFocusLost(evt);
            }
        });
        convFild.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                convFildKeyPressed(evt);
            }
        });

        nConCombo.setModel(new DefaultComboBoxModel());
        nConCombo.setMinimumSize(new java.awt.Dimension(246, 25));
        nConCombo.setPreferredSize(new java.awt.Dimension(246, 25));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), nConCombo, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        nConCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nConComboActionPerformed(evt);
            }
        });
        nConCombo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                nConComboKeyPressed(evt);
            }
        });

        valorFild.setDocument(Documents.getDocuments().DigitaDouble());

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), valorFild, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        valorFild.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                valorFildFocusLost(evt);
            }
        });
        valorFild.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                valorFildKeyReleased(evt);
            }
        });

        jLabel2.setText("Valor");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jLabel6)
                            .addComponent(obsFild, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jCStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(valorFild)
                            .addComponent(jLabel2))
                        .addContainerGap())
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(osFild, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(atenFild, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jLabel4)
                            .addComponent(convFild, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(nConCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addContainerGap())
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jLabel3)
                                .addGap(80, 80, 80))))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(osFild, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(atenFild, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(convFild, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(nConCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jCStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(valorFild, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(obsFild, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {atenFild, convFild, jCStatus, nConCombo, obsFild, osFild, valorFild});

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        newButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botoes/new.png"))); // NOI18N
        newButton.setToolTipText("Novo");
        newButton.setDisabledIcon(null);
        newButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newButtonActionPerformed(evt);
            }
        });

        infoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botoes/Info.png"))); // NOI18N
        infoButton.setToolTipText("Informação");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), infoButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        infoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                infoButtonActionPerformed(evt);
            }
        });

        refreshButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botoes/refresh.png"))); // NOI18N
        refreshButton.setToolTipText("Atualizar");
        refreshButton.setDisabledIcon(null);
        refreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refreshButtonActionPerformed(evt);
            }
        });

        saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botoes/save.png"))); // NOI18N
        saveButton.setToolTipText("Salvar");
        saveButton.setDisabledIcon(null);
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        uploadBoton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botoes/upload.png"))); // NOI18N
        uploadBoton.setToolTipText("Upload");
        uploadBoton.setEnabled(false);
        uploadBoton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uploadBotonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(uploadBoton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(numLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(newButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(infoButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(refreshButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(numLabel)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(uploadBoton, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(saveButton)
                            .addComponent(refreshButton)
                            .addComponent(infoButton)
                            .addComponent(newButton))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        masterTable.setModel(dtm);
        jScrollTabela.setViewportView(masterTable);

        jBarradeProgresso.setBackground(new java.awt.Color(255, 255, 255));
        jBarradeProgresso.setStringPainted(true);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jScrollTabela)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jBarradeProgresso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(jScrollTabela, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBarradeProgresso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    private void obsFildFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_obsFildFocusLost
        obs(obsFild.getText());
    }//GEN-LAST:event_obsFildFocusLost

    private void obsFildActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_obsFildActionPerformed
        // TODO add your handling code here:
        jCStatus.requestFocus();
    }//GEN-LAST:event_obsFildActionPerformed

    private void jCStatusFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jCStatusFocusLost
        // TODO add your handling code here:
        status();
    }//GEN-LAST:event_jCStatusFocusLost

    private void jCStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCStatusActionPerformed
        // TODO add your handling code here:
        status();
    }//GEN-LAST:event_jCStatusActionPerformed

    private void jCStatusKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jCStatusKeyPressed
        // TODO add your handling code here:
        if(KeyEvent.VK_ENTER == evt.getKeyCode()){
            status();
            jCStatus.nextFocus();
        }
    }//GEN-LAST:event_jCStatusKeyPressed

    private void osFildKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_osFildKeyReleased
        // TODO add your handling code here:
        if (KeyEvent.VK_ENTER == evt.getKeyCode()) {
            ErroMensagens.getInstancia().close();
            modelaOS();
            if (ErroMensagens.getInstancia().isErroEnable()) {
                ErroMensagens.getInstancia().AtencaoMensagem("OS invalida");
                osFild.requestFocus();
                ErroMensagens.getInstancia().close();
            } else {
                atenFild.requestFocus();
            }
        }
    }//GEN-LAST:event_osFildKeyReleased

    private void atenFildFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_atenFildFocusGained
        // TODO add your handling code here:
        atendente = true;
    }//GEN-LAST:event_atenFildFocusGained

    private void atenFildFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_atenFildFocusLost
        // TODO add your handling code here:
        atenCod(atenFild.getText().replace("USER", ""));
        if (ErroMensagens.getInstancia().isErroEnable()) {
            ErroMensagens.getInstancia().AtencaoMensagem("Atendente não encontrado");
            ErroMensagens.getInstancia().close();
        } else {
            convFild.requestFocus();
        }
    }//GEN-LAST:event_atenFildFocusLost

    private void atenFildKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_atenFildKeyPressed
        // TODO add your handling code here:
        if (KeyEvent.VK_ENTER == evt.getKeyCode()) {
            atenCod(atenFild.getText().replace("USER", ""));
            if (ErroMensagens.getInstancia().isErroEnable()) {
                ErroMensagens.getInstancia().AtencaoMensagem("Atendente não encontrado");
                ErroMensagens.getInstancia().close();
            } else {
                convFild.requestFocus();
            }
        }
    }//GEN-LAST:event_atenFildKeyPressed

    private void atenFildKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_atenFildKeyReleased
        // TODO add your handling code here:
        atenFild.setText(atenFild.getText().toUpperCase());
    }//GEN-LAST:event_atenFildKeyReleased

    private void convFildFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_convFildFocusGained
        // TODO add your handling code here:
        convenio = true;
    }//GEN-LAST:event_convFildFocusGained

    private void convFildFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_convFildFocusLost
        // TODO add your handling code here:
        convCod(convFild.getText());
        if (ErroMensagens.getInstancia().isErroEnable()) {
            ErroMensagens.getInstancia().AtencaoMensagem("Convenio não encontrado");
            ErroMensagens.getInstancia().close();
        } else {
            nConCombo.requestFocus();
        }
    }//GEN-LAST:event_convFildFocusLost

    private void convFildKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_convFildKeyPressed
        // TODO add your handling code here:
        convFild.setText(convFild.getText().toUpperCase());
        if (KeyEvent.VK_ENTER == evt.getKeyCode()) {
            convCod(convFild.getText());
            if (ErroMensagens.getInstancia().isErroEnable()) {
                ErroMensagens.getInstancia().AtencaoMensagem("Convenio não encontrado");
                ErroMensagens.getInstancia().close();
            } else {
                nConCombo.requestFocus();
            }
        }
    }//GEN-LAST:event_convFildKeyPressed

    private void nConComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nConComboActionPerformed
        try {
            nCombo(nConCombo.getSelectedItem().toString());
        } catch (NullPointerException e) {
            nCombo("");
        }
    }//GEN-LAST:event_nConComboActionPerformed

    private void nConComboKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nConComboKeyPressed
        // TODO add your handling code here:
        if (KeyEvent.VK_ENTER == evt.getKeyCode()) {
            try {
                nCombo(nConCombo.getSelectedItem().toString());
            } catch (NullPointerException e) {
                nCombo("");
            }
            obsFild.requestFocus();
        }
    }//GEN-LAST:event_nConComboKeyPressed

    private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
        novo();
        jCStatus.setSelectedIndex(0);
        nConCombo.setSelectedIndex(0);
    }//GEN-LAST:event_newButtonActionPerformed

    private void infoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_infoButtonActionPerformed

        openDielog();
        list = dao.refresh(list);
        mostraPesquisa();

    }//GEN-LAST:event_infoButtonActionPerformed

    private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
        list = dao.refresh(list);
        mostraPesquisa();
    }//GEN-LAST:event_refreshButtonActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        try {
            list = dao.Save(list);
        } catch (RollbackException rex) {
            dao.getEntityManager().getTransaction().begin();
            ErroMensagens.getInstancia().ErroMensagem("Houve um erro ao salvar este lote, \n tente novamente!");
        }
        mostraPesquisa();
    }//GEN-LAST:event_saveButtonActionPerformed

    private void uploadBotonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uploadBotonActionPerformed

        if (nConCombo.getSelectedItem() != null) {
            upload();
        } else {
            ErroMensagens.getInstancia().AtencaoMensagem("A inconsistencia deve ser selecionada!");
        }

    }//GEN-LAST:event_uploadBotonActionPerformed

    private void valorFildFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_valorFildFocusLost
        
        valor(valorFild.getText());
        
    }//GEN-LAST:event_valorFildFocusLost


    private void valorFildKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_valorFildKeyReleased
        // TODO add your handling code here:
        if(KeyEvent.VK_ENTER == evt.getKeyCode()){
            masterTable.setValueAt(valorFild.getText(), masterTable.getSelectedRow(), 9);
        }
    }//GEN-LAST:event_valorFildKeyReleased


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField atenFild;
    private javax.swing.JTextField convFild;
    private javax.swing.JButton infoButton;
    private javax.swing.JProgressBar jBarradeProgresso;
    private javax.swing.JComboBox jCStatus;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollTabela;
    private javax.swing.JTable masterTable;
    private javax.swing.JComboBox nConCombo;
    private javax.swing.JButton newButton;
    private javax.swing.JLabel numLabel;
    private javax.swing.JTextField obsFild;
    private javax.swing.JTextField osFild;
    private javax.swing.JButton refreshButton;
    private javax.swing.JButton saveButton;
    private javax.swing.JButton uploadBoton;
    private javax.swing.JTextField valorFild;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    private EntityManager emf;
    private List<SftOutputGlos> list;
    private List<SftOutputGlos> listHist;
    private List<SftInputUnid> boxUnid;
    private List<MascaraConvenio> mascara;
    private List<SftInputNcon> boxNcon;
    private List<SftInputAten> boxAten;
    private List<SftInputStat> boxStatus;
    private List<Convenio> boxConv;
    private List<String> codAten;
    private List<Integer> codUnid;
    private List<String> codMascara;
    private OutputGlosCtrl dao;
    public static JDGlos dialog;
    public static JDGlosHist hist;
    private boolean atendente;
    private boolean convenio;
    private DefaultTableModel dtm = new DefaultTableModel(null, new String[]{
    "Usuario", "Data", "Numero OS", "Unidade", "Atendente", "Convênio", 
        "Não Conformidade","Observação", "Status", "Valor"});
    private ListSelectionModel lsm;
    //fim declaração de variavel
    
    //construtor
    private void iniciarComponentes() {
        emf = CriaConexao.getInstance().getEntityManager();
        dao = new OutputGlosCtrl(emf);
        dao.getEntityManager().getTransaction().begin();
        listarPesquisa();
        listarBox();
    }
    
    //pesquisa padrão do banco de dados
    private void listarPesquisa() {
        list = dao.getGlosMonth();
        boxUnid = new Business().findAll(SftInputUnid.class);
        boxAten = new Business().findAll(SftInputAten.class);
        mascara = new Business().findAll(MascaraConvenio.class);
        boxNcon = new Business().findAll(SftInputNcon.class);
        boxStatus = new Business().findAll(SftInputStat.class);
        boxConv = new Business().findAll(Convenio.class);
        mostraPesquisa();    
    }
    
    //busca por OS
    public void pesquisa(String os){
        list = dao.getGlosList(os);
        mostraPesquisa();
    }
    
    //preencher os combobox com os Objetos
    private void listarBox() {
        codAten = new ArrayList<>();
        for (SftInputAten sftAten : boxAten) {
            codAten.add(sftAten.getAtenUsUsaten().replace("USER", ""));
        }
        codUnid = new ArrayList<>();
        for (SftInputUnid sftUnid : boxUnid) {
            codUnid.add(sftUnid.getUnidCodCodigo());
        }

        nConCombo.removeAllItems();
        nConCombo.addItem(null);
        List<SftInputNcon> removeNcon = new ArrayList<>();
        for (SftInputNcon sftNcon : boxNcon) {
            if (sftNcon.getNconNmNmncon().contains("ZZ ")) {
                removeNcon.add(sftNcon);
            } else {
                nConCombo.addItem(sftNcon.getNconNmNmncon());
            }
        }
        boxNcon.removeAll(removeNcon);
        
        jCStatus.removeAllItems();
        jCStatus.addItem(null);
        List<SftInputStat> removeStatus = new ArrayList<>();
        for (SftInputStat sftStatus : boxStatus) {
            if(sftStatus.getStatusNmDescricao().contains("ZZ ")){
                removeStatus.add(sftStatus);
            }else{
                jCStatus.addItem(sftStatus.getStatusNmDescricao());
            }
        }
        
        codMascara = new ArrayList<>();
        for (Convenio sftConvenios : boxConv) {
            codMascara.add(String.valueOf(sftConvenios.getCodigo()));
        }
    }
    
    /*
        "Usuario", "Data", "Numero OS", "Unidade", "Atendente", "Convênio", 
        "Não Conformidade","Observação", "Status", "Valor"});
    */
    //exibição
    private void mostraPesquisa() {
        while(dtm.getRowCount() > 0){
            dtm.removeRow(0);
        }
        if(list.isEmpty()){
            //ErroMensagens.getInstancia().InformacaoMensagem("Nenhum resultado encontrado!");
            numLabel.setText("Nenhum resultado encontrado!");
        }else{
            numLabel.setText(String.valueOf(list.size()));
            String[] linha = new String[]{null, null, null, null ,null ,null, null, null, null,null};
            int i = 0;
            for (SftOutputGlos sftGlos : list) {
                try{
                    int size = sftGlos.getSftCtrlHistoricoList().size()-1;
                    dtm.addRow(linha);
                    dtm.setValueAt(((sftGlos.getSftCtrlHistoricoList() != null) ? sftGlos.getSftCtrlHistoricoList()
                            .get(size).getUsuariosId().getLogin() : null), i, 0);//user
                    SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
                    dtm.setValueAt(formato.format(sftGlos.getSftCtrlHistoricoList()
                            .get(size).getHistDtRegis()), i, 1);//Data
                    dtm.setValueAt(sftGlos.getGlosOsNumos(), i, 2);
                    dtm.setValueAt(((sftGlos.getFkUnid() != null) ? sftGlos.getFkUnid()
                            .getUnidNmNmunid() : null), i, 3);//mostra unidade se existir
                    dtm.setValueAt(((sftGlos.getFkAten() != null) ? sftGlos.getFkAten()
                            .getAtenNmNmaten() : null), i, 4);//mostra atendente
                    dtm.setValueAt(((sftGlos.getFkConv() != null) ? sftGlos.getFkConv()
                            .getMascaraConvenioId().getDescricao() : null), i, 5);//mostra convenio
                    dtm.setValueAt(((sftGlos.getFkNcon() != null) ? sftGlos.getFkNcon()
                            .getNconNmNmncon() : null), i, 6);//mostra não conformidade
                    dtm.setValueAt(sftGlos.getGlosObObsglos(), i, 7);
                    dtm.setValueAt(((sftGlos.getFkStat() != null) ? sftGlos.getFkStat()
                            .getStatusNmDescricao() : null), i, 8);//mostra descricao
                    dtm.setValueAt(sftGlos.getGlosVlVlos(), i, 9);//mostra valor
                    i++;                    
                }catch(NullPointerException | ArrayIndexOutOfBoundsException e){
                    System.out.println("Erro na visualização");
                }
            }
        }
    }
    
    public void jTTabelaLinhaSelecionada(JTable masterTable){
        try{
            osFild.setText(list.get(masterTable.getSelectedRow()).getGlosOsNumos());
            obsFild.setText(list.get(masterTable.getSelectedRow()).getGlosObObsglos());
            jCStatus.setSelectedItem(list.get(masterTable.getSelectedRow()).getFkStat().getStatusNmDescricao());
            atenFild.setText(list.get(masterTable.getSelectedRow()).getFkAten().getAtenNmNmaten());
            convFild.setText(list.get(masterTable.getSelectedRow()).getFkConv().getMascaraConvenioId().getDescricao());
            nConCombo.setSelectedItem(list.get(masterTable.getSelectedRow()).getFkNcon().getNconNmNmncon());
            valorFild.setText(String.valueOf(list.get(masterTable.getSelectedRow()).getGlosVlVlos()));
        } catch(ArrayIndexOutOfBoundsException a){
            osFild.setText("");
            atenFild.setText("");
            convFild.setText("");
            nConCombo.setSelectedItem("");
            obsFild.setText("");
            jCStatus.setSelectedItem("");
            valorFild.setText("");
        } catch(NullPointerException e){
        }
    }
    //fim exibição padrao
    
    //inicio cadastro
    private void novo() {
        br.entidade.sft.SftOutputGlos s = new br.entidade.sft.SftOutputGlos();
        s.setSftCtrlHistoricoList(
                Logger.getInstance().glosRegistros("cadastro", "nova glosa", 
                        new ArrayList<SftCtrlHistorico>(),s));
        Date dat = new Date(new java.util.Date().getTime());
        s.setGlosDtRegis(dat);
        dao.create(s);
        list.add(s);
        mostraPesquisa();
        int row = list.size() -1;
        masterTable.setRowSelectionInterval(row, row);
        masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true));
    }
   
    //Adicionar OS
    private void adicionaOS(String texto) throws NumberFormatException {
        //adiciona na lista e no tabela a OS encotrada
        if (teste(texto)) {
            SftOutputGlos s = list.get(masterTable.getSelectedRow());
            s.setGlosOsNumos(texto);
            masterTable.setValueAt(osFild.getText(), masterTable.getSelectedRow(), 2);
            int unid = Integer.parseInt(texto.split("-")[0]);
            int cod = codUnid.indexOf(unid);
            s.setSftCtrlHistoricoList(
                    Logger.getInstance().glosRegistros("adiciona", texto,
                            s.getSftCtrlHistoricoList(),s));
            //Adiciona na lista e na tabela a unidade encontrada
            list.get(masterTable.getSelectedRow()).setFkUnid(boxUnid.get(cod));
            masterTable.setValueAt(boxUnid.get(cod).getUnidNmNmunid(), masterTable.getSelectedRow(), 3);
            
            //adiciona user de Hospitais
            if(unid == 10){
                atendente = true;
                atenCod("MERID");
            }   
            if(unid == 26){
                atendente = true;
                atenCod("SRITA");
            }
        } else {
            osFild.setText("");
            ErroMensagens.getInstancia().AtencaoMensagem("OS já cadastrada!");
        }
        
    }
    //testa a existencia de uma OS
    private boolean teste(String texto) {
        List<SftOutputGlos> incos = dao.getGlosList(texto);
        if (incos.isEmpty()) {
            return true;
        } else {
            return false;
        }
    }
    
     //modelagem de OS
    private void modelaOS() throws NumberFormatException {
        // TODO add your handling code here:
        try {
            //Modela texto recebido de osFild
            StringBuilder sb = new StringBuilder(osFild.getText().replace("-", ""));
            sb.insert(3, "-");
            sb.insert(9, "-");
            String texto = sb.toString();
            osFild.setText(texto);
            adicionaOS(texto);
        } catch (StringIndexOutOfBoundsException | ArrayIndexOutOfBoundsException s) {
            if (!"".equals(osFild.getText())) {
                ErroMensagens.getInstancia().Errado();
                osFild.setText("");
                osFild.requestFocus();
            }
        }
    }
    //fim adiciona OS
    //Inicio JDealog
    public void openDielog() {
        dialog = new JDGlos(this, true);
        dialog.setVisible(true);
    }

    public void openHistorico() {
        hist = new JDGlosHist(this, true);
        hist.setVisible(true);
    }
    
    public List<SftOutputGlos> toRemove() {
        int[] selected = masterTable.getSelectedRows();
        List<br.entidade.sft.SftOutputGlos> toRemove = new ArrayList<>(selected.length);
        for (int idx = 0; idx < selected.length; idx++) {
            br.entidade.sft.SftOutputGlos s = list.get(masterTable.convertRowIndexToModel(selected[idx]));
            toRemove.add(s);
        }
        return toRemove;
    }

    public void setHist(List<SftOutputGlos> list) {
        this.listHist = list;
    }

    public List<SftOutputGlos> getHist() {
        return listHist;
    }
    //Fim JDialog
    //incio atendente
    private void atenCod(String user){
        int cod;
        if (atendente) {
            try {
                Integer.parseInt(user);
                cod = codAten.indexOf(user);
                if (cod != -1) {
                    atenEncontrado(cod);
                } else {
                    ErroMensagens.getInstancia().Errado();
                    atenFild.setText("");
                    atenFild.requestFocus();
                }
            } catch (NumberFormatException n) {
                if (user.contains("MERID")) {
                    user = "FATURAMENTO MERIDIONAL";
                }
                if (user.contains("SRITA")) {
                    user = "FATURAMENTO SANTA RITA";
                }
                cod = codAten.indexOf(user);
                if(cod != -1){
                    atenEncontrado(cod);
                }
                if (atendente) {
                    if (!atenFild.getText().isEmpty()) {
                        for (int i = 0; i < boxAten.size(); i++) {
                            if (boxAten.get(i).getAtenNmNmaten().contains(atenFild.getText())) {
                                atenEncontrado(i);
                                return;
                            }
                        }
                        ErroMensagens.getInstancia().Errado();
                        atenFild.setText("");
                    }
                }
            }
        }
    }
    
    private void atenEncontrado(int cod) {
        SftOutputGlos s = list.get(masterTable.getSelectedRow());
        SftInputAten get = boxAten.get(cod);
        atenFild.setText(get.getAtenNmNmaten());
        s.setFkAten(get);
        s.setSftCtrlHistoricoList(
                Logger.getInstance().glosRegistros("atendente", get.getAtenNmNmaten(),
                        s.getSftCtrlHistoricoList(),s));
        masterTable.setValueAt(get.getAtenNmNmaten(), masterTable.getSelectedRow(), 4);
        atendente = false;
    }
    //fim atendente
    
    //incio convênio
    private void convCod(String conv) {
        // TODO add your handling code here:
        if (convenio) {
            try {
                Integer.parseInt(conv);
                int cod = codMascara.indexOf(conv);
                if(cod != -1){
                    convEncontrado(cod);
                }else{
                    ErroMensagens.getInstancia().Errado();
                    convFild.setText("");
                    convFild.requestFocus();
                }
            } catch (NumberFormatException e) {
                if (!convFild.getText().isEmpty()) {
                    if (convenio) {
                        for (int i = 0; i < mascara.size(); i++) {
                            if (boxConv.get(i).getMascaraConvenioId().getDescricao().contains(convFild.getText())) {
                                convEncontrado(i);
                                return;
                            }
                        }
                        ErroMensagens.getInstancia().Errado();
                        convFild.setText("");
                        convFild.requestFocus();
                    }
                }
            }
        }
    }

    private void convEncontrado(int cod) {
        SftOutputGlos s = list.get(masterTable.getSelectedRow());
        Convenio get = boxConv.get(cod);
        convFild.setText(get.getMascaraConvenioId().getDescricao());
        s.setFkConv(get);
        s.setSftCtrlHistoricoList(
                Logger.getInstance().glosRegistros("convenio", get.getDescricao(),
                        s.getSftCtrlHistoricoList(),s));
        masterTable.setValueAt(get.getMascaraConvenioId().getDescricao(), masterTable.getSelectedRow(), 5);
        convenio = false;
    }
    //fim convênio
    
    //Incio Status
    private void status() {
        // TODO add your handling code here:
        if (masterTable.getSelectedRow() != -1) {
            for (SftInputStat sftStatus : boxStatus) {
                if (jCStatus.getSelectedItem() != null && sftStatus.hashCode() == jCStatus.getSelectedItem().hashCode()) {
                    SftOutputGlos s = list.get(masterTable.getSelectedRow());
                    s.setFkStat(sftStatus);
                    masterTable.setValueAt(jCStatus.getSelectedItem(), masterTable.getSelectedRow(), 8);
                    s.setSftCtrlHistoricoList(
                            Logger.getInstance().glosRegistros("status", jCStatus.getSelectedItem().toString(),
                                    s.getSftCtrlHistoricoList(),s));
                }
            }
        }
    }
    //não conformidade metodo unico
    private SftInputNcon nCombo(String nCon) {
        // TODO add your handling code here:
        if (masterTable.getSelectedRow() != -1) {
            if (nConCombo.getSelectedItem() != null) {
                for (SftInputNcon sftNcon : boxNcon) {
                    if (sftNcon.getNconNmNmncon().equals(nCon)) {
                        SftOutputGlos s = list.get(masterTable.getSelectedRow());
                        s.setFkNcon(sftNcon);
                        masterTable.setValueAt(sftNcon.getNconNmNmncon(), masterTable.getSelectedRow(), 6);
                        s.setSftCtrlHistoricoList(
                                Logger.getInstance().glosRegistros("inconsistencia", sftNcon.getNconNmNmncon(),
                                        s.getSftCtrlHistoricoList(),s));
                        return sftNcon;
                    }
                }
            } else {
                masterTable.setValueAt("", masterTable.getSelectedRow(), 6);
            }
        }
        return null;
    }
    //adiciona Observação
    private void obs(String obs) {
        // TODO add your handling code here:
        SftOutputGlos s = list.get(masterTable.getSelectedRow());
        s.setGlosObObsglos(obs);
        masterTable.setValueAt(obs, masterTable.getSelectedRow(), 7);
        s.setSftCtrlHistoricoList(
                Logger.getInstance().glosRegistros("observacao", obs,
                        s.getSftCtrlHistoricoList(),s));
    }
    
    private void valor(String valor) {
        // TODO add your handling code here:
        try {
            SftOutputGlos s = list.get(masterTable.getSelectedRow());
            s.setGlosVlVlos(Double.valueOf(valor));
            s.setSftCtrlHistoricoList(
                Logger.getInstance().glosRegistros("valor", valor,
                        s.getSftCtrlHistoricoList(),s));
            masterTable.setValueAt(valor, masterTable.getSelectedRow(), 9);
            saveButton.requestFocus();
        } catch (NumberFormatException e) {
            ErroMensagens.getInstancia().ErroMensagem("Precisa ser inserido um valor numerico.");
            valorFild.setText("");
        }
    }
    //fim do cadastro de OS
    
    //Upload não foi implementado para esta versão
    private void upload() {
    }
            
}
